//
//  XDCommentImageCell.m
//  XDEducation
//
//  Created by apple on 2017/4/20.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDCommentImageCell.h"


@interface XDCommentImageCell ()
/** imageview数组 */
@property(nonatomic,strong) NSMutableArray *imageViewArr;
@end

@implementation XDCommentImageCell

+(instancetype)cellWithTableView:(UITableView *)tableView imageArr:(NSArray *)imageArr{
    
    static NSString *cellId = @"XDCommentImageCell";
    XDCommentImageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        
        
        cell = [[XDCommentImageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId imageArr:(NSArray *)imageArr];
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier imageArr:(NSArray *)imageArr{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
    
        CGFloat buttonW = 50;
        
        CGFloat padding = (ScreenW - 4*buttonW)/5;
        
        for (int i = 0; i < imageArr.count; i ++) {
            
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(padding + (padding + buttonW)*i, 10, buttonW, buttonW)];
            imageView.image = [UIImage imageNamed:@"list_icon_add_image_default"];
            imageView.tag = i;
            [self.contentView addSubview:imageView];
            
            imageView.userInteractionEnabled = YES;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imageViewClicked:)];
            [imageView addGestureRecognizer:tap];
            
            [_imageViewArr addObject:imageView];
            
            if (imageView.tag != 0) {
                imageView.hidden = YES;
            }
        }
        
    }
    return self;
}

-(void)imageViewClicked:(UITapGestureRecognizer *)tap{
    
    
    NSLog(@"%ld",tap.view.tag);

    //UIImageView *imageView = _imageViewArr[tap.view.tag + 1];
    
    
}
@end
